package ch07.test.cn.cvs.service;

import ch07.test.cn.cvs.dao.SupplierMapper;
import ch07.test.cn.cvs.entity.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional
@Service("supplierService")
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;


    @Override
    public List<Supplier> selectShow(Supplier supplier1) {
        try {
            return supplierMapper.selectShow(supplier1);
        } catch (RuntimeException e) {
            throw e;
        }
    }

    @Override
    public int add(Supplier supplier) {
        int result=0;
        try{
            if(supplierMapper.add(supplier)>=1){
                result=1;
            }
        }catch (RuntimeException e){
            e.printStackTrace();
            throw e;
        }
        return result;
    }

    @Override
    public int del(int id) {
        return supplierMapper.del(id);
    }

    @Override
    public int update(Supplier supplier,int id) {
        return supplierMapper.update(supplier,id);
    }

    public SupplierMapper getSupplierMapper() {
        return supplierMapper;
    }

    public void setSupplierMapper(SupplierMapper supplierMapper) {
        this.supplierMapper = supplierMapper;
    }
}
